<?php
class entries extends connect { 
	function EntryAsArray($res) { // returns MySQL results as a php array
		$entry=array();
		while($result = mysql_fetch_assoc($res)){
			$arr_result=array();
			$c=0;
			while ($c < mysql_num_fields($res)) {        
				$field = mysql_fetch_field($res, $c);    
				$arr_result[$field -> name] = $result[$field -> name];
				$c++;
			}    
			$entry = $arr_result;
		}    
		return $entry;
	}
	function EntriesAsArray($res) { // returns MySQL results as a php array
		$entries=array();
		$i=0;
		while($result = mysql_fetch_assoc($res)){
			$arr_result=array();
			$c=0;
			while ($c < mysql_num_fields($res)) {
				$field = mysql_fetch_field($res, $c);
				$arr_result[$field -> name] = $result[$field -> name];
				$c++;
			}    
			$entries[$i] = $arr_result;
			$i++;
		}
		return $entries;
	}
	function AddEntry($data) {
		$query = "INSERT INTO `{$this->TableEntries}` (`".implode('`, `', array_keys($data))."`) VALUES ('".implode("', '", $data)."')";
		echo $query;
		$response = parent::$this->query($query);
		return $response;
	}
	function GetEntryByID($entryID) {
		$query = "SELECT * FROM`{$this->TableEntries}` WHERE entryID = $entryID";
		$response = $this->query($query);
		return $response;
	}
	function SetEntryByID($entryID,$Field,$Data) {
		$query = "UPDATE `{$this->TableEntries}` SET $Field='{$Data}' WHERE entryID = '$entryID'";
	}
	function DeleteEntryByID($entryID) { 
		$query = "DELETE FROM `{$this->TableEntries}` WHERE entryID = `$entryID`";
	}
	
	function GetEntryTitleByID($entryID) { 
		$query = "SELECT entryTitle FROM`{$this->TableEntries}` WHERE entryID = $entryID";
		$response = $this->query($query);
		return $response;
	}
	
	function ShowEntries($max=50,$offset=0) { 
		$query = "SELECT * FROM`{$this->TableEntries}` LIMIT $offset,$max";
		$response = $this->query($query);
		return $response;
	}
	
}
?>